$(function(){
    // 获取数据
    var currentPage = 1;
    var pageSize = 3;
    function render() {
        $.ajax({
            type: 'get',
            url: '/category/queryTopCategoryPaging',
            data: {
                page: currentPage,
                pageSize: pageSize
            },
            dataType: 'json',
            success: function(res){
                console.log(res);
                $('tbody').html(template('tmp', res));
                setPage(res.total);
            }

        })
    }

    render();

    // 模态框处理
    $('#addform').bootstrapValidator({
        //1、 指定不校验的类型，默认，可以不设置
        excluded: [':disabled', ':hidden', ':not(:visible)'],
        // 2、指定校验时的图表显示，默认是bootsrap风格
        feedbackIcons: {
            valid: 'glyphicon glyphicon-ok',
            invalid: 'glyphicon glyphicon-remove',
            validating: 'glyphicon glyphicon-refresh'
        },
        fields: {
            categoryName: {
                validators: {
                    notEmpty: {
                    message: '请输入一级分类'
                    }
                   
                }
            },
        }
    });
  

    // 分页功能
    function setPage(total){
        $('#paginator').bootstrapPaginator({
            bootstrapMajorVersion: 3,
            currentPage: currentPage,
            totalPage: Math.ceil(total /  pageSize),
            onPageClicked: function(event, originalEvent, type, page){
                console.log(page);
                currentPage = page;
                render();
            }
        });
    }
})